<template>
  <view>
    <view class="store_modules">
      <!--主内容-->
      <view class="store_main" @click="apply_mini('complete')">
        <!--左侧区域-->
        <view class="store_title_img">
          <view class="total_img bind_mini">
            <text class="iconfont icon-shouquan"></text>
          </view>
          <view class="store_main_title">
            <view class="store_title">绑定小程序</view>
            <view class="store_sub_title"
              >无需复杂操作即可拥有微信小程序商城</view
            >
          </view>
        </view>
        <!--右侧icon-->
        <view class="store_right">
          <view class="iconfont icon-arrow-right"></view>
        </view>
      </view>
      <!--提示信息-->
      <view class="store_tips" v-if="progress <= 3">
        <view class="tips_title">您提交的内容有如下错误：</view>
        <view class="tips_msg">{{ msg }}</view>
      </view>
    </view>

    <view class="store_modules">
      <!--主内容-->
      <view class="store_main" @click="apply_mini('GetPhone')">
        <!--左侧区域-->
        <view class="store_title_img">
          <view class="total_img pay_bind">
            <text class="iconfont icon-maidan-l"></text>
          </view>
          <view class="store_main_title">
            <view class="store_title">申请手机号权限</view>
            <view class="store_sub_title">便于获取用户手机号权限</view>
          </view>
        </view>
        <!--右侧icon-->
        <view class="store_right">
          <view class="iconfont icon-arrow-right"></view>
        </view>
      </view>
      <!--提示信息-->
      <view class="store_tips" v-if="progress == 4">
        <view class="tips_title">您提交的内容有如下错误：</view>
        <view class="tips_msg">{{ msg }}</view>
      </view>
    </view>
    <view class="store_modules">
      <!--主内容-->
      <view class="store_main" @click="apply_mini('aliQrcode')">
        <!--左侧区域-->
        <view class="store_title_img">
          <view class="total_img qrcode_bind">
            <text class="iconfont icon-QRcode"></text>
          </view>
          <view class="store_main_title">
            <view class="store_title">绑定聚合码</view>
            <view class="store_sub_title">快速绑定关联聚合收款码</view>
          </view>
        </view>
        <!--右侧icon-->
        <view class="store_right">
          <view class="iconfont icon-arrow-right"></view>
        </view>
      </view>
      <!--提示信息-->
      <view class="store_tips" v-if="progress == 5">
        <view class="tips_title">您提交的内容有如下错误：</view>
        <view class="tips_msg">{{ msg }}</view>
      </view>
    </view>
    <template>
      <view>
        <u-modal v-model="show" :content="content" @confirm="GetAuth" @cancel="cancelAuth" show-cancel-button="true" :confirm-text="confirm_text" :cancel-text="cancel_text"></u-modal>
      </view>
    </template>
  </view>
</template>

<script>
export default {
  data() {
    return {
      storeId: 0,
      msg: "",
      progress: 0,
      mini_id: 0,
			business_model: 1,
      show: false,
      content: '此支付宝账户是否为企业或个体工商户',
      confirm_text: "去认证",
      cancel_text: "取消"
    };
  },
  onLoad(e) {
    if (e.id) {
      this.storeId = e.id;
    }
  },
	
	onShow(){
		this.getCompleteInfo();
	},
	
  methods: {
    //去认证
    GetAuth(){
      let status = this.status;
      let storeId = this.storeId;
      uni.navigateTo({
        url: `/new_store/main/ali_qrcode?status=${status}&id=${storeId}`
      });
    },
    //取消操作
    async cancelAuth(){
      if (parseInt(this.status) === -2) {
        const res = await this.$allrequest.newStore.GetParam(
            {
              bind_store_id: this.storeId,
              status : 1
            }
        );
      }
    },
    // 获取小程序完善信息
    async getCompleteInfo() {
      const res = await this.$allrequest.newStore.getAliProgress(
        {
          bind_store_id: this.storeId,
        },
        true
      );
      if (res.code == 0) {
        this.msg = res.msg;
        this.progress = res.data.progress;
        this.mini_id = res.data.mini_id;
        this.qrcode_id = res.data.qrcode_id;
        this.status = res.data.status;
        if (this.progress === 0 && this.status === -1) {
          this.show = true;
          this.content = "该账户正在认证，是否重新生成";
          this.confirm_text ="确认"
          this.cancel_text = "取消"

        } else if (this.progress === 0 && this.status === -2) {
          this.show = true;
          this.content = "此支付宝账户是否为企业或个体工商户";
          this.confirm_text ="否 去认证"
          this.cancel_text = "已经是企业"
        }
      }
    },

    apply_mini(e) {
      let { storeId, mini_id, progress, qrcode_id, status } = this,
        url = "";

      if (progress === 6) {
        uni.navigateTo({
          url: `/salesman/checkShop/checkShop`,
        });
        return;
      }

      url += `/new_store/ali/${e}`;
      switch (e) {
        case "complete":
          // 4等待审核
          // 0.1.2.3 跳转绑定小程序
          if (progress > 3) {
            uni.showToast({
              title: "此项已完成~",
              icon: "none",
            });
            return;
          }

          url += `?id=${storeId}&mini_id=${mini_id}`;
          break;

        case "GetPhone":
          if (progress < 4) {
            uni.showToast({
              title: "其他项目未完成~",
              icon: "none",
            });
            return;
          } else if (progress > 4) {
            uni.showToast({ title: "此项已完成~", icon: "none" });
            return;
          }

          url += `?id=${storeId}&mini_id=${mini_id}`;
          break;

        case "aliQrcode":
          if (progress < 5) {
            uni.showToast({ title: "其他项目未完成~", icon: "none"  });
            return;
          }

          url += `?mini_id=${mini_id}&qrcode_id=${qrcode_id}&status=${status}`;
          break;
      }

      uni.navigateTo({
        url,
      });
    },
  },
};
</script>

<style scoped>
.store_main,
.store_title_img {
  display: flex;
  align-items: center;
}

.store_modules {
  padding: 34rpx 0;
  border-bottom: 1px solid #ececec;
}

.total_img {
  width: 80rpx;
  height: 80rpx;
  border-radius: 50%;
  background: #dcdcdc;
  display: flex;
  justify-content: center;
  align-items: center;
}

.total_img text {
  font-size: 40rpx;
  color: #fff;
}

.bind_mini {
  background: #31aafa;
}

.pay_bind {
  background: #fbb13e;
}

.qrcode_bind {
  background: #754ccd;
}
.store_right view {
  font-size: 20rpx;
}

.store_main {
  justify-content: space-between;
  padding: 0 20rpx;
}

.store_main_title {
  margin-left: 20rpx;
}

.store_title {
  font-weight: 700;
  color: #101010;
  font-size: 32rpx;
  margin-bottom: 10rpx;
}

.store_right {
  color: #b1b1b1;
}

.store_sub_title {
  font-weight: 500;
  color: #adadad;
  font-size: 26rpx;
}

.store_tips {
  margin: 38rpx 20rpx 0;
  padding: 16rpx 20rpx;
  background: #f5f5f5;
  border-radius: 8rpx;
}

.tips_title {
  font-weight: 600;
  color: #2d2d2d;
  margin-bottom: 10rpx;
  font-size: 24rpx;
}

.tips_msg {
  font-weight: 600;
  color: #fb5252;
  line-height: 40rpx;
  font-size: 24rpx;
}
</style>
